package cn.com.truelore;

import cn.com.truelore.R;
import cn.com.truelore.base.BaseActivity;
import cn.com.truelore.common.CommonAlertDialog;
import cn.com.truelore.common.Constants;

import android.content.Intent;
import android.graphics.BitmapFactory.Options;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageButton;

/**
 * 程序的主界面
 * 
 * @author Administrator
 * 
 */
public class HomeActivity extends BaseActivity {

	public HomeActivity() {
		super(R.layout.home);
	}

	/**
	 * 初始化按钮事件
	 */
	public void initButtonClick() {
		// 获取Corn的图标
		ImageButton imgBtn = (ImageButton) findViewById(R.id.imgBtnHomeCorn);
		imgBtn.setOnClickListener(new ImageButton.OnClickListener() {
			// 追加一个页面点击事件
			public void onClick(View v) {
				Intent it = new Intent(HomeActivity.this, ZhaoBiao_FuWuActivity.class);
				Bundle bd = new Bundle();
				bd.putInt("tab", Constants.TYPE_CORN);
				it.putExtras(bd);
				startActivity(it);
			}
		});
		imgBtn = (ImageButton) findViewById(R.id.imgBtnHomeSoy);
		imgBtn.setOnClickListener(new ImageButton.OnClickListener() {
			// 追加一个页面点击事件
			public void onClick(View v) {
				Intent it = new Intent(HomeActivity.this, PriceActivity.class);
				Bundle bd = new Bundle();
				bd.putInt("tab", Constants.TYPE_SOY);
				it.putExtras(bd);
				startActivity(it);
			}
		});
		imgBtn = (ImageButton) findViewById(R.id.imgBtnHomeWheat);
		imgBtn.setOnClickListener(new ImageButton.OnClickListener() {
			// 追加一个页面点击事件
			public void onClick(View v) {
				Intent it = new Intent(HomeActivity.this, PriceActivity.class);
				Bundle bd = new Bundle();
				bd.putInt("tab", Constants.TYPE_WHEAT);
				it.putExtras(bd);
				startActivity(it);
			}
		});
		imgBtn = (ImageButton) findViewById(R.id.imgBtnHomeSetting);
		imgBtn.setOnClickListener(new ImageButton.OnClickListener() {
			// 追加一个页面点击事件
			public void onClick(View v) {
				Intent it = new Intent(HomeActivity.this, PriceActivity.class);
				Bundle bd = new Bundle();
				bd.putInt("tab", Constants.TYPE_SETTINGS);
				it.putExtras(bd);
				startActivity(it);
			}
		});

		imgBtn = (ImageButton) findViewById(R.id.imgBtnHomeFeedBack);
		imgBtn.setOnClickListener(new ImageButton.OnClickListener() {
			// 追加一个页面点击事件
			public void onClick(View v) {
				imgBtnHomeFeedBack_OnClick(v);
			}
		});

		imgBtn = (ImageButton) findViewById(R.id.imgBtnHomeAbout);
		imgBtn.setOnClickListener(new ImageButton.OnClickListener() {
			// 追加一个页面点击事件
			public void onClick(View v) {
				Intent it = new Intent(HomeActivity.this, AboutActivity.class);
				startActivity(it);
			}
		});

	}

	private void imgBtnHomeFeedBack_OnClick(View v) {
		Intent email = new Intent(android.content.Intent.ACTION_SEND);
		// email.setType("text/plain");
		email.setType("message/rfc822");
		/*
		 * String[] emailReciver = new String[] { this.getResources().getString(
		 * R.string.mailsenderemailto) };
		 */
		String[] emailReciver = new String[] { "Technical Support<"
				+ super.getResources().getString(R.string.mailsenderemailto)
				+ ">" };
		String emailSubject = this.getResources().getString(
				R.string.mailsendersubject);

		String strContext = "";
		strContext = strContext + "Model:" + Build.MODEL + "\n";
		strContext = strContext + "Device ID:" + Build.ID + "\n";
		strContext = strContext + "Device Name:" + Build.DEVICE + "\n";
		strContext = strContext + "Version:" + Build.VERSION.RELEASE + "\n\n";
		strContext = strContext + "Send from my phone";

		email.putExtra(android.content.Intent.EXTRA_EMAIL, emailReciver);
		email.putExtra(android.content.Intent.EXTRA_SUBJECT, emailSubject);
		email.putExtra(android.content.Intent.EXTRA_TEXT, strContext);
		startActivity(Intent.createChooser(email,
				"Please select the email sender"));
		/*
		 * Intent intent = new Intent(HomeActivity.this,
		 * MailSendActivity.class); startActivity(intent);
		 */
	}

	/**
	 * on key down
	 */
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			// 杀死本进程
			super.exitApplication();
			return true;

		}
		return false;
	}
}
